package simulation;
import java.util.LinkedList;

import events.Event;


public class Echeancier {
	
	private final static int ONEHOUR = 3600;
	
	public static int T9H = 9*ONEHOUR;
	public static int T11H = T9H+(2*ONEHOUR);
	public static int T13H = T11H+(2*ONEHOUR);
	public static int T14H = T13H+ONEHOUR;
	public static int T14H30 = T14H+(ONEHOUR/2);
	public static int T17H = T14H+(3*ONEHOUR);
	
	private LinkedList<Event> listeEvents;

	public Echeancier () {
		listeEvents = new LinkedList<Event>();
	}

	public void ajouter(Event e) {
		int pos = 0;
		while ( pos < listeEvents.size() ) {
			if (((Event) listeEvents.get(pos)).date > e.date) {
				listeEvents.add(pos, e);
				return;
			} else {
				pos++;
			}
		}
		listeEvents.add(pos, e);
	}

	public void vide(){ listeEvents.clear(); }

	public Event retourneEtEnlevePremier () {		
		Event e = (Event) listeEvents.getFirst();
		listeEvents.removeFirst();
		return e;
	}

	public boolean estVide() {
		return (listeEvents.size() == 0);
	}

	public String afficheLaSituation () {
		String s = new String("");
		int index = 0;
		while ( index < listeEvents.size() ) {
			s = s+((Event) listeEvents.get(index)).toString()+"\n";
			index++;
		}
		s+=("\n\n");
		return s;
	}

	public boolean isNotEmpty() {
		return ! listeEvents.isEmpty();
	}
	
	public static String toHour(int seconds){
		int hours = seconds/3600;
		int Tmin = seconds%3600;
		int min = Tmin/60;
		int sec = Tmin%60;
		return "\n\t\t\t"+hours+"h"+min+"m"+sec+"s";
	}
}
